import axios from 'axios';

import * as actionTypes from './actionTypes';

const changeDetail = (data) => ({
    type: actionTypes.INIT_DETAIL,
    title: data.title,
    content: data.content
});

export const initDetail = (id) => {
    return async (dispatch) => {
        try {
            const val = await axios.get("/mock/api/detail.json?id="+id);
            const data = val.data;
            if (data.success) {
                await dispatch(changeDetail(data.data));
            } else {
                console.error(data.msg);
            }
        } catch(e) {
            console.error("网络发送失败:" + e);
        }
    }
}
